#pragma once
#include "cocos2d.h"
#include "json/rapidjson.h"
#include "json/document.h"
#include "Prefabs.h"
USING_NS_CC;
using namespace std;

class ConfigMgrBase
{
public:
	ConfigMgrBase();
	virtual ~ConfigMgrBase();
	int getCount();
	void loadFile(string strPath);
	virtual void prase(rapidjson::Value& valueDt)=0;

	template<class T>
	T getDataByID(int nId){
		for (auto data : m_vecData){
			if (data->nId == nId){
				return static_cast<T>(data);
			}
		}
		return nullptr;
	}

	template<class T>
	T getDataByIndex(int nIndex){
		if (nIndex >= 0 && nIndex < m_vecData.size())
			return static_cast<T>(m_vecData[nIndex]);
		return nullptr;
	}

	template<class T>
	vector<T> getAllData(){
		vector<T> vecData;
		for (auto data : m_vecData){
			T temple = static_cast<T>(data);
			vecData.push_back(temple);
		}
		return vecData;
	}

protected:
	vector<DataBase*> m_vecData;
};

